﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Assist;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;
using YArchitech.Revit;
using YArchitech.Revit.RevitExtension;
using YJKArchMethodLibrary.Utils;
using YJKArchMethodLibrary.Utils.SelectMaterial;
using YJKFamilyLibDataManager;
using YJKRamp.BarrierFreeRampKit;

namespace YJKRamp.Forms
{
	public partial class BarrierFreeRampForm : System.Windows.Forms.Form
	{
		public BarrierFreeRampForm.ResultType DlgCloseType
		{
			get
			{
				return this.m_nDlgCloseType;
			}
		}

		public int RampSlope
		{
			get
			{
				string value = this.m_strRampSlope.Remove(0, 2);
				return Convert.ToInt32(value);
			}
		}

		public double TopElev
		{
			get
			{
				return AssistFunc.mmToFeet((double)this.m_nTopElev);
			}
		}

		public double MaxHeight
		{
			get
			{
				return AssistFunc.mmToFeet((double)this.m_nMaxHeight);
			}
		}

		public double RampWidth
		{
			get
			{
				return AssistFunc.mmToFeet((double)this.m_nRampWidth);
			}
		}

		public double PlatWidth
		{
			get
			{
				return AssistFunc.mmToFeet((double)this.m_nPlatWidth);
			}
		}

		public double FloorThick
		{
			get
			{
				return (double)this.m_nFloorThick;
			}
		}

		public double RampLength1
		{
			get
			{
				return AssistFunc.mmToFeet((double)this.m_nRampLength1);
			}
		}

		public double RampLength2
		{
			get
			{
				return AssistFunc.mmToFeet((double)this.m_nRampLength2);
			}
		}

		public double RampLength3
		{
			get
			{
				return AssistFunc.mmToFeet((double)this.m_nRampLength3);
			}
		}

		public double RampLength4
		{
			get
			{
				return AssistFunc.mmToFeet((double)this.m_nRampLength4);
			}
		}

		public double DrawAngle
		{
			get
			{
				return this.m_dDrawAngle / 180.0 * Math.PI;
			}
			set
			{
				this.m_dDrawAngle = value / Math.PI * 180.0;
			}
		}

		public ElementId MaterialId
		{
			get
			{
				return this.m_idMaterial;
			}
		}

		public FamilySymbol LeftRailSymbol
		{
			get
			{
				return this.m_leftRailSymbol;
			}
		}

		public FamilySymbol RightRailSymbol
		{
			get
			{
				return this.m_rightRailSymbol;
			}
		}

		public FamilySymbol EndRailSymbol
		{
			get
			{
				return this.m_endRailSymbol;
			}
		}

		public BarrierFreeRampForm(ExternalCommandData cmdData, bool bEditRamp)
		{
			this.m_cmdData = cmdData;
			this.m_strRampSlope = BarrierFreeRampForm.m_lstRampSlope[0];
			this.m_bEditRamp = bEditRamp;
			this.m_RampPreviewer = new Previewer(this, 210, 55, 370, 255, 1u);
			base.MouseWheel += this.m_RampPreviewer.MouseWheel;
			this.InitializeComponent();
		}

		public XYZ GetRealInsertPoint()
		{
			double platWidth = this.PlatWidth;
			double num = this.RampWidth / 2.0;
			double num2 = platWidth - num;
			XYZ xyz = new XYZ(1.0, 0.0, 0.0);
			XYZ xyz2 = new XYZ(0.0, 1.0, 0.0);
			XYZ xyz3 = new XYZ(0.0, 0.0, 0.0);
			XYZ xyz4 = new XYZ(this.RampLength1, 0.0, 0.0);
			List<XYZ> list = new List<XYZ>();
			if (this.m_strRampStyle == "直线型")
			{
				list.Add(xyz3 + xyz2 * num);
				list.Add(xyz4 + xyz2 * num);
				list.Add(xyz4 - xyz2 * num);
				list.Add(xyz3 - xyz2 * num);
			}
			else if (this.m_strRampStyle == "直角型")
			{
				XYZ xyz5 = xyz4 + xyz * num2;
				XYZ xyz6 = xyz5 + xyz2 * (num2 + this.RampLength2);
				XYZ item = xyz5 + xyz * num - xyz2 * num;
				list.Add(xyz3 + xyz2 * num);
				list.Add(xyz3 - xyz2 * num);
				list.Add(item);
				list.Add(xyz6 + xyz * num);
				list.Add(xyz6 - xyz * num);
			}
			else if (this.m_strRampStyle == "折返型1")
			{
				XYZ xyz7 = xyz4 + xyz * num2;
				XYZ xyz8 = xyz7 + xyz2 * (2.0 * num2 + this.RampLength2);
				XYZ xyz9 = xyz8 - xyz * (num2 + this.RampLength3);
				XYZ item2 = xyz7 + xyz * num - xyz2 * num;
				XYZ item3 = xyz8 + xyz * num + xyz2 * num;
				list.Add(xyz3 + xyz2 * num);
				list.Add(xyz3 - xyz2 * num);
				list.Add(item2);
				list.Add(item3);
				list.Add(xyz9 + xyz2 * num);
				list.Add(xyz9 - xyz2 * num);
			}
			else if (this.m_strRampStyle == "折返型2")
			{
				XYZ xyz10 = xyz4 + xyz * num2;
				XYZ xyz11 = xyz10 + xyz2 * (2.0 * num2 + this.RampLength2);
				XYZ xyz12 = xyz11 - xyz * (2.0 * num2 + this.RampLength3);
				XYZ xyz13 = xyz12 + xyz2 * (num2 + this.RampLength4);
				XYZ item4 = xyz10 + xyz * num - xyz2 * num;
				XYZ item5 = xyz11 + xyz * num + xyz2 * num;
				XYZ item6 = xyz12 - xyz * num - xyz2 * num;
				list.Add(xyz3 + xyz2 * num);
				list.Add(xyz3 - xyz2 * num);
				list.Add(item4);
				list.Add(item5);
				list.Add(xyz13 + xyz * num);
				list.Add(xyz13 - xyz * num);
				list.Add(item6);
			}
			if (this.m_nPosionIndex >= list.Count)
			{
				this.m_nPosionIndex = 0;
			}
			XYZ xyz14 = list[this.m_nPosionIndex];
			if (this.m_bTurnLeftRight)
			{
				xyz14 = new XYZ(-xyz14.X, xyz14.Y, xyz14.Z);
			}
			if (this.m_bTurnUpDown)
			{
				xyz14 = new XYZ(xyz14.X, -xyz14.Y, xyz14.Z);
			}
			if (this.DrawAngle > 0.0001)
			{
				xyz14 = Geometry.RotateTo(xyz14, this.DrawAngle, XYZ.BasisZ);
			}
			return xyz14;
		}

		public double GetBottomElev()
		{
			double num = 0.0;
			if (this.m_lstBaseLine.Count > 0)
			{
				num += this.RampLength1;
			}
			if (this.m_lstBaseLine.Count > 1)
			{
				num += this.RampLength2;
			}
			if (this.m_lstBaseLine.Count > 2)
			{
				num += this.RampLength3;
			}
			if (this.m_lstBaseLine.Count > 3)
			{
				num += this.RampLength4;
			}
			double num2 = num / (double)this.RampSlope;
			return this.TopElev - num2;
		}

		public bool DlgDataFromStringList(List<string> lstDlgData)
		{
			if (lstDlgData.Count < 21)
			{
				return false;
			}
			this.m_nTopElev = Convert.ToInt32(lstDlgData[0]);
			this.m_strRampSlope = lstDlgData[1];
			this.m_nMaxHeight = Convert.ToInt32(lstDlgData[2]);
			this.m_nRampWidth = Convert.ToInt32(lstDlgData[3]);
			this.m_nPlatWidth = Convert.ToInt32(lstDlgData[4]);
			this.m_nFloorThick = Convert.ToInt32(lstDlgData[5]);
			this.m_nRampLength1 = Convert.ToInt32(lstDlgData[6]);
			this.m_nRampLength2 = Convert.ToInt32(lstDlgData[7]);
			this.m_nRampLength3 = Convert.ToInt32(lstDlgData[8]);
			this.m_nRampLength4 = Convert.ToInt32(lstDlgData[9]);
			this.m_bSymmetric = Convert.ToBoolean(lstDlgData[10]);
			this.m_strRampStructStyle = lstDlgData[11];
			this.m_strRampStyle = lstDlgData[12];
			this.m_strMaterial = lstDlgData[13];
			this.m_bDrawRailingLeft = Convert.ToBoolean(lstDlgData[14]);
			this.m_bDrawRailingRight = Convert.ToBoolean(lstDlgData[15]);
			this.m_bTurnUpDown = Convert.ToBoolean(lstDlgData[16]);
			this.m_bTurnLeftRight = Convert.ToBoolean(lstDlgData[17]);
			this.m_bMarkDirection = Convert.ToBoolean(lstDlgData[18]);
			this.m_dDrawAngle = Convert.ToDouble(lstDlgData[19]);
			this.m_nPosionIndex = Convert.ToInt32(lstDlgData[20]);
			return true;
		}

		public List<string> DlgDataToStringList()
		{
			return new List<string>
			{
				this.m_nTopElev.ToString(),
				this.m_strRampSlope,
				this.m_nMaxHeight.ToString(),
				this.m_nRampWidth.ToString(),
				this.m_nPlatWidth.ToString(),
				this.m_nFloorThick.ToString(),
				this.m_nRampLength1.ToString(),
				this.m_nRampLength2.ToString(),
				this.m_nRampLength3.ToString(),
				this.m_nRampLength4.ToString(),
				this.m_bSymmetric.ToString(),
				this.m_strRampStructStyle,
				this.m_strRampStyle,
				this.m_strMaterial,
				this.m_bDrawRailingLeft.ToString(),
				this.m_bDrawRailingRight.ToString(),
				this.m_bTurnUpDown.ToString(),
				this.m_bTurnLeftRight.ToString(),
				this.m_bMarkDirection.ToString(),
				this.m_dDrawAngle.ToString(),
				this.m_nPosionIndex.ToString()
			};
		}

		private bool LoadFamily()
		{
			this.m_lstRailSymbol = new List<FamilySymbol>();
			new List<FamilySymbol>();
			try
			{
				string defFamilyLibPath = FamilyLibDatabase.GetDefFamilyLibPath();
				string versionNumber = this.m_cmdData.Application.Application.VersionNumber;
				FileInfo fileInfo = new FileInfo(defFamilyLibPath + "\\Architecture" + versionNumber + ".db");
				if (!fileInfo.Exists)
				{
					YJKMessageBox.Show(fileInfo.FullName + "\n没有检测到本地族库，请安装族库。");
					return false;
				}
				Document document = this.m_cmdData.Application.ActiveUIDocument.Document;
				FamilyLibDatabase familyLibDatabase = new SqliteDatabase(fileInfo.FullName);
				DbCategory dbCategory = familyLibDatabase.CategoryTable["其它"];
				List<DbFamily> allFamilies = dbCategory.GetAllFamilies(false, CheckType.All);
				foreach (DbFamily dbFamily in allFamilies)
				{
					if (dbFamily.Name == "坡道扶手")
					{
						Family family = dbFamily.Load(document);
						using (List<FamilySymbol>.Enumerator enumerator2 = family.GetSymbols().GetEnumerator())
						{
							while (enumerator2.MoveNext())
							{
								FamilySymbol familySymbol = enumerator2.Current;
								if (familySymbol != null)
								{
									this.m_lstRailSymbol.Add(familySymbol);
								}
							}
							continue;
						}
					}
					if (dbFamily.Name == "扶手末端")
					{
						Family family2 = dbFamily.Load(document);
						foreach (FamilySymbol familySymbol2 in family2.GetSymbols())
						{
							if (familySymbol2 != null)
							{
								this.m_endRailSymbol = familySymbol2;
							}
						}
					}
				}
			}
			catch
			{
				YJKMessageBox.Show("族库中未能找到扶手，请用最新族库");
				return false;
			}
			return true;
		}

		private void InitComboxData()
		{
			this.cmbSlope.Items.Clear();
			foreach (string item in BarrierFreeRampForm.m_lstRampSlope)
			{
				this.cmbSlope.Items.Add(item);
			}
			this.cmbStructStyle.Items.Clear();
			foreach (string item2 in BarrierFreeRampForm.m_lstRampStruct)
			{
				this.cmbStructStyle.Items.Add(item2);
			}
			this.cmbRampStyle.Items.Clear();
			foreach (string item3 in BarrierFreeRampForm.m_lstRampStyle)
			{
				this.cmbRampStyle.Items.Add(item3);
			}
			this.cmbRailingLeft.Items.Clear();
			this.cmbRailingRight.Items.Clear();
			foreach (FamilySymbol familySymbol in this.m_lstRailSymbol)
			{
				this.cmbRailingLeft.Items.Add(familySymbol.Name);
				this.cmbRailingRight.Items.Add(familySymbol.Name);
			}
			this.cmbRampThick.Items.Clear();
			foreach (string item4 in BarrierFreeRampForm.m_lstFloorThick)
			{
				this.cmbRampThick.Items.Add(item4);
			}
		}

		private void InitMaterial()
		{
			this.m_idMaterial = null;
			Document document = this.m_cmdData.Application.ActiveUIDocument.Document;
			FilteredElementCollector filteredElementCollector = new FilteredElementCollector(document);
			ICollection<Element> collection = filteredElementCollector.OfClass(typeof(Material)).ToElements();
			foreach (Element element in collection)
			{
				Material material = element as Material;
				if (material.Name.CompareTo(this.m_strMaterial) == 0)
				{
					this.m_idMaterial = material.Id;
					break;
				}
			}
			if (this.m_idMaterial == null)
			{
				IEnumerator<Element> enumerator2 = collection.GetEnumerator();
				{
					if (enumerator2.MoveNext())
					{
						Element element2 = enumerator2.Current;
						Material material2 = element2 as Material;
						this.m_strMaterial = material2.Name;
						this.m_idMaterial = material2.Id;
					}
				}
			}
		}

		private void InitRailSymbol()
		{
			this.m_leftRailSymbol = null;
			this.m_rightRailSymbol = null;
			foreach (FamilySymbol familySymbol in this.m_lstRailSymbol)
			{
				if (familySymbol.Name == this.m_strRailingNameLeft)
				{
					this.m_leftRailSymbol = familySymbol;
				}
				if (familySymbol.Name == this.m_strRailingNameRight)
				{
					this.m_rightRailSymbol = familySymbol;
				}
			}
			if (this.m_leftRailSymbol == null && this.m_lstRailSymbol.Count > 0)
			{
				this.m_leftRailSymbol = this.m_lstRailSymbol[0];
				this.m_strRailingNameLeft = this.m_leftRailSymbol.Name;
			}
			if (this.m_rightRailSymbol == null && this.m_lstRailSymbol.Count > 0)
			{
				this.m_rightRailSymbol = this.m_lstRailSymbol[0];
				this.m_strRailingNameRight = this.m_rightRailSymbol.Name;
			}
		}

		private void InitSlopeMaxValue()
		{
			this.cmbMaxHeight.Items.Clear();
			this.cmbMaxHeight.Items.Add("300");
			this.m_nSlopeMaxHeight = 300;
			this.m_nSlopeMaxLength = 2400;
			this.m_nSlope = this.RampSlope;
			if (this.m_nSlope >= 9)
			{
				this.cmbMaxHeight.Items.Add("450");
				this.m_nSlopeMaxHeight = 450;
				this.m_nSlopeMaxLength = 4050;
			}
			if (this.m_nSlope >= 10)
			{
				this.cmbMaxHeight.Items.Add("600");
				this.m_nSlopeMaxHeight = 600;
				this.m_nSlopeMaxLength = 6000;
			}
			if (this.m_nSlope >= 12)
			{
				this.cmbMaxHeight.Items.Add("750");
				this.m_nSlopeMaxHeight = 750;
				this.m_nSlopeMaxLength = 9000;
			}
			if (this.m_nSlope >= 16)
			{
				this.cmbMaxHeight.Items.Add("900");
				this.m_nSlopeMaxHeight = 900;
				this.m_nSlopeMaxLength = 14400;
			}
			if (this.m_nSlope >= 18)
			{
				this.cmbMaxHeight.Items.Add("1050");
				this.m_nSlopeMaxHeight = 1050;
				this.m_nSlopeMaxLength = 18900;
			}
			if (this.m_nSlope >= 20)
			{
				this.cmbMaxHeight.Items.Add("1200");
				this.m_nSlopeMaxHeight = 1200;
				this.m_nSlopeMaxLength = 24000;
			}
		}

		private void SetDlgItemEnable()
		{
			this.cmbRampStyle.Enabled = !this.m_bEditRamp;
			this.cmbRailingLeft.Enabled = this.m_bDrawRailingLeft;
			this.cmbRailingRight.Enabled = this.m_bDrawRailingRight;
			if (this.m_strRampStructStyle == "整体")
			{
				this.cmbRampThick.Enabled = false;
			}
			else
			{
				this.cmbRampThick.Enabled = true;
			}
			if (this.m_strRampStyle == "直线型")
			{
				this.chkSymmetric.Enabled = false;
				this.txtPlatWidth.Enabled = false;
				this.txtRampLength2.Enabled = false;
				this.txtRampLength3.Enabled = false;
				this.txtRampLength4.Enabled = false;
				return;
			}
			if (this.m_strRampStyle == "直角型")
			{
				this.chkSymmetric.Enabled = false;
				this.txtPlatWidth.Enabled = true;
				this.txtRampLength2.Enabled = true;
				this.txtRampLength3.Enabled = false;
				this.txtRampLength4.Enabled = false;
				return;
			}
			if (this.m_strRampStyle == "折返型1")
			{
				this.chkSymmetric.Enabled = true;
				this.txtPlatWidth.Enabled = true;
				this.txtRampLength2.Enabled = true;
				this.txtRampLength3.Enabled = !this.m_bSymmetric;
				this.txtRampLength4.Enabled = false;
				return;
			}
			this.chkSymmetric.Enabled = true;
			this.txtPlatWidth.Enabled = true;
			this.txtRampLength2.Enabled = true;
			this.txtRampLength3.Enabled = !this.m_bSymmetric;
			this.txtRampLength4.Enabled = !this.m_bSymmetric;
		}

		protected override void DefWndProc(ref Message m)
		{
			try
			{
				if (m.Msg == 1125)
				{
					this.RefreshPreview();
				}
				else
				{
					base.DefWndProc(ref m);
				}
			}
			catch (Exception)
			{
				base.DefWndProc(ref m);
			}
		}

		private void RefreshPreview()
		{
			List<TextNoteInfo> list = new List<TextNoteInfo>();
			List<CurveInfo> list2 = new List<CurveInfo>();
			this.m_lstBaseLine = new List<Line>();
			try
			{
				double num = 50.0;
				double num2 = 1000.0;
				double num3 = 400.0;
				double num4 = 500.0;
				double num5 = 240.0;
				double dOffset = num5 - 20.0;
				double num6 = num4 - num5;
				PenColor color = PenColor.PC_Black;
				PenColor color2 = PenColor.PC_Blue;
				PenColor color3 = PenColor.PC_Gray;
				PenColor color4 = PenColor.PC_Red;
				XYZ xyz = new XYZ(1.0, 0.0, 0.0);
				XYZ xyz2 = new XYZ(0.0, 1.0, 0.0);
				XYZ xyz3 = new XYZ(0.0, 0.0, 0.0);
				XYZ xyz4 = new XYZ(num2, 0.0, 0.0);
				List<XYZ> list3 = new List<XYZ>();
				Line curve;
				if (this.m_strRampStyle == "直线型")
				{
					this.m_lstBaseLine.Add(YJKLineEx.YJKGetBound(xyz3, xyz4));
					this.DrawDim(xyz3 + xyz2 * num5, xyz4 + xyz2 * num5, num, "坡段1长度", color2, list, list2);
					this.DrawDim(xyz4 + xyz2 * num5, xyz4 - xyz2 * num5, num, "坡道宽度", color2, list, list2);
					list3.Add(xyz3 + xyz2 * num5);
					list3.Add(xyz4 + xyz2 * num5);
					list3.Add(xyz4 - xyz2 * num5);
					list3.Add(xyz3 - xyz2 * num5);
				}
				else if (this.m_strRampStyle == "直角型")
				{
					XYZ startPoint = xyz3;
					XYZ xyz5 = xyz4 + xyz * num6;
					this.m_lstBaseLine.Add(YJKLineEx.YJKGetBound(startPoint, xyz5));
					XYZ xyz6 = xyz5 + xyz2 * (num6 + num3);
					this.m_lstBaseLine.Add(YJKLineEx.YJKGetBound(xyz5, xyz6));
					curve = YJKLineEx.YJKGetBound(xyz4 - xyz2 * num5, xyz4 + xyz2 * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					XYZ xyz7 = xyz5 + xyz2 * num6;
					curve = YJKLineEx.YJKGetBound(xyz7 - xyz * num5, xyz7 + xyz * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					XYZ xyz8 = xyz5 + xyz * num5 - xyz2 * num5;
					this.DrawDim(xyz4 - xyz2 * num5, xyz3 - xyz2 * num5, num, "坡段1长度", color2, list, list2);
					this.DrawDim(xyz8, xyz4 - xyz2 * num5, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz8 + xyz2 * num4, xyz8, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz6 + xyz * num5, xyz8 + xyz2 * num4, num, "坡段2长度", color2, list, list2);
					this.DrawDim(xyz6 - xyz * num5, xyz6 + xyz * num5, num, "坡道宽度", color2, list, list2);
					list3.Add(xyz3 + xyz2 * num5);
					list3.Add(xyz3 - xyz2 * num5);
					list3.Add(xyz8);
					list3.Add(xyz6 + xyz * num5);
					list3.Add(xyz6 - xyz * num5);
				}
				else if (this.m_strRampStyle == "折返型1")
				{
					XYZ startPoint2 = xyz3;
					XYZ xyz9 = xyz4 + xyz * num6;
					this.m_lstBaseLine.Add(YJKLineEx.YJKGetBound(startPoint2, xyz9));
					XYZ xyz10 = xyz9 + xyz2 * (2.0 * num6 + num3);
					this.m_lstBaseLine.Add(YJKLineEx.YJKGetBound(xyz9, xyz10));
					XYZ xyz11 = xyz10 - xyz * (num6 + num2);
					this.m_lstBaseLine.Add(YJKLineEx.YJKGetBound(xyz10, xyz11));
					curve = YJKLineEx.YJKGetBound(xyz4 - xyz2 * num5, xyz4 + xyz2 * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					XYZ xyz12 = xyz9 + xyz2 * num6;
					curve = YJKLineEx.YJKGetBound(xyz12 - xyz * num5, xyz12 + xyz * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					xyz12 = xyz10 - xyz2 * num6;
					curve = YJKLineEx.YJKGetBound(xyz12 - xyz * num5, xyz12 + xyz * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					xyz12 = xyz10 - xyz * num6;
					curve = YJKLineEx.YJKGetBound(xyz12 - xyz2 * num5, xyz12 + xyz2 * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					XYZ xyz13 = xyz9 + xyz * num5 - xyz2 * num5;
					XYZ xyz14 = xyz10 + xyz * num5 + xyz2 * num5;
					this.DrawDim(xyz4 - xyz2 * num5, xyz3 - xyz2 * num5, num, "坡段1长度", color2, list, list2);
					this.DrawDim(xyz13, xyz4 - xyz2 * num5, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz13 + xyz2 * num4, xyz13, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz14 - xyz2 * num4, xyz13 + xyz2 * num4, num, "坡段2长度", color2, list, list2);
					this.DrawDim(xyz14, xyz14 - xyz2 * num4, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz14 - xyz * num4, xyz14, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz11 + xyz2 * num5, xyz14 - xyz * num4, num, "坡段3长度", color2, list, list2);
					this.DrawDim(xyz11 - xyz2 * num5, xyz11 + xyz2 * num5, num, "坡道宽度", color2, list, list2);
					list3.Add(xyz3 + xyz2 * num5);
					list3.Add(xyz3 - xyz2 * num5);
					list3.Add(xyz13);
					list3.Add(xyz14);
					list3.Add(xyz11 + xyz2 * num5);
					list3.Add(xyz11 - xyz2 * num5);
				}
				else if (this.m_strRampStyle == "折返型2")
				{
					XYZ startPoint3 = xyz3;
					XYZ xyz15 = xyz4 + xyz * num6;
					this.m_lstBaseLine.Add(YJKLineEx.YJKGetBound(startPoint3, xyz15));
					XYZ xyz16 = xyz15 + xyz2 * (2.0 * num6 + num3);
					this.m_lstBaseLine.Add(YJKLineEx.YJKGetBound(xyz15, xyz16));
					XYZ xyz17 = xyz16 - xyz * (2.0 * num6 + num2);
					this.m_lstBaseLine.Add(YJKLineEx.YJKGetBound(xyz16, xyz17));
					XYZ xyz18 = xyz17 + xyz2 * (num6 + num3);
					this.m_lstBaseLine.Add(YJKLineEx.YJKGetBound(xyz17, xyz18));
					curve = YJKLineEx.YJKGetBound(xyz4 - xyz2 * num5, xyz4 + xyz2 * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					XYZ xyz19 = xyz15 + xyz2 * num6;
					curve = YJKLineEx.YJKGetBound(xyz19 - xyz * num5, xyz19 + xyz * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					xyz19 = xyz16 - xyz2 * num6;
					curve = YJKLineEx.YJKGetBound(xyz19 - xyz * num5, xyz19 + xyz * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					xyz19 = xyz16 - xyz * num6;
					curve = YJKLineEx.YJKGetBound(xyz19 - xyz2 * num5, xyz19 + xyz2 * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					xyz19 = xyz17 + xyz * num6;
					curve = YJKLineEx.YJKGetBound(xyz19 - xyz2 * num5, xyz19 + xyz2 * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					xyz19 = xyz17 + xyz2 * num6;
					curve = YJKLineEx.YJKGetBound(xyz19 - xyz * num5, xyz19 + xyz * num5);
					list2.Add(new CurveInfo(curve, color3, 1f));
					XYZ xyz20 = xyz15 + xyz * num5 - xyz2 * num5;
					XYZ xyz21 = xyz16 + xyz * num5 + xyz2 * num5;
					XYZ xyz22 = xyz17 - xyz * num5 - xyz2 * num5;
					this.DrawDim(xyz4 - xyz2 * num5, xyz3 - xyz2 * num5, num, "坡段1长度", color2, list, list2);
					this.DrawDim(xyz20, xyz4 - xyz2 * num5, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz20 + xyz2 * num4, xyz20, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz21 - xyz2 * num4, xyz20 + xyz2 * num4, num, "坡段2长度", color2, list, list2);
					this.DrawDim(xyz21, xyz21 - xyz2 * num4, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz21 - xyz * num4, xyz21, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz17 + xyz2 * num5 + xyz * num6, xyz21 - xyz * num4, num, "坡段3长度", color2, list, list2);
					this.DrawDim(xyz22 + xyz * num4, xyz22, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz22, xyz22 + xyz2 * num4, num, "平台宽度", color2, list, list2);
					this.DrawDim(xyz22 + xyz2 * num4, xyz18 - xyz * num5, num, "坡段4长度", color2, list, list2);
					this.DrawDim(xyz18 - xyz * num5, xyz18 + xyz * num5, num, "坡道宽度", color2, list, list2);
					list3.Add(xyz3 + xyz2 * num5);
					list3.Add(xyz3 - xyz2 * num5);
					list3.Add(xyz20);
					list3.Add(xyz21);
					list3.Add(xyz18 + xyz * num5);
					list3.Add(xyz18 - xyz * num5);
					list3.Add(xyz22);
				}
				TextNoteInfo item = new TextNoteInfo("向上", color2, num, xyz3 - xyz * num * 3.0, 4.0 * num, 1.5 * num, 0.0);
				list.Add(item);
				if (this.m_nPosionIndex >= list3.Count)
				{
					this.m_nPosionIndex = 0;
				}
				XYZ xyz23 = list3[this.m_nPosionIndex];
				XYZ xyz24 = Geometry.RotateTo(xyz, 0.78539816339744828, XYZ.BasisZ);
				curve = YJKLineEx.YJKGetBound(xyz23 - xyz24 * num, xyz23 + xyz24 * num);
				list2.Add(new CurveInfo(curve, color4, 1f));
				xyz24 = Geometry.RotateTo(xyz, -0.78539816339744828, XYZ.BasisZ);
				curve = YJKLineEx.YJKGetBound(xyz23 - xyz24 * num, xyz23 + xyz24 * num);
				list2.Add(new CurveInfo(curve, color4, 1f));
				this.TransformElements(this.DrawAngle, this.m_bTurnLeftRight, this.m_bTurnUpDown, list2, list);
				this.TransformLines(this.DrawAngle, this.m_bTurnLeftRight, this.m_bTurnUpDown, this.m_lstBaseLine);
				List<Line> list4 = this.OffsetLines(this.m_lstBaseLine, num5, true);
				foreach (Line curve2 in list4)
				{
					list2.Add(new CurveInfo(curve2, color, 1f));
				}
				List<Line> list5 = this.OffsetLines(this.m_lstBaseLine, num5, false);
				foreach (Line curve3 in list5)
				{
					list2.Add(new CurveInfo(curve3, color, 1f));
				}
				Line line = this.m_lstBaseLine[0];
				XYZ hyendPoint = line.GetEndPoint(0);
				XYZ xyz25 = Geometry.RotateTo(line.Direction, Math.PI*.5, XYZ.BasisZ);
				curve = YJKLineEx.YJKGetBound(hyendPoint - xyz25.Normalize() * num5, hyendPoint + xyz25.Normalize() * num5);
				list2.Add(new CurveInfo(curve, color3, 1f));
				Line line2 = this.m_lstBaseLine[this.m_lstBaseLine.Count - 1];
				XYZ hyendPoint2 = line2.GetEndPoint(1);
				xyz25 = Geometry.RotateTo(line2.Direction, Math.PI*.5, XYZ.BasisZ);
				curve = YJKLineEx.YJKGetBound(hyendPoint2 - xyz25.Normalize() * num5, hyendPoint2 + xyz25.Normalize() * num5);
				list2.Add(new CurveInfo(curve, color3, 1f));
				if (this.m_bDrawRailingLeft)
				{
					List<Line> list6 = this.OffsetLines(this.m_lstBaseLine, dOffset, true);
					foreach (Line curve4 in list6)
					{
						list2.Add(new CurveInfo(curve4, color3, 1f));
					}
				}
				if (this.m_bDrawRailingRight)
				{
					List<Line> list7 = this.OffsetLines(this.m_lstBaseLine, dOffset, false);
					foreach (Line curve5 in list7)
					{
						list2.Add(new CurveInfo(curve5, color3, 1f));
					}
				}
				if (this.m_bMarkDirection)
				{
					this.DrawArrow(this.m_lstBaseLine, num * 0.6, color2, list2);
				}
			}
			catch (Exception ex)
			{
				YJKMessageBox.Show(ex.Message);
			}
			this.m_RampPreviewer.TextNotes = list;
			this.m_RampPreviewer.Curves = list2;
		}

		private void DrawDim(XYZ ptBase1, XYZ ptBase2, double dTextH, string sDimText, PenColor Color, List<TextNoteInfo> lstText, List<CurveInfo> lstLine)
		{
			XYZ xyz = (ptBase2 - ptBase1).Normalize();
			XYZ xyz2 = Geometry.RotateTo(xyz, Math.PI*.5, XYZ.BasisZ);
			Line curve = YJKLineEx.YJKGetBound(ptBase1, ptBase1 + xyz2 * 2.0 * dTextH);
			lstLine.Add(new CurveInfo(curve, Color, 1f));
			curve = YJKLineEx.YJKGetBound(ptBase2, ptBase2 + xyz2 * 2.0 * dTextH);
			lstLine.Add(new CurveInfo(curve, Color, 1f));
			ptBase1 += xyz2 * 1.5 * dTextH;
			ptBase2 += xyz2 * 1.5 * dTextH;
			XYZ xyz3 = Geometry.RotateTo(xyz, 0.78539816339744828, XYZ.BasisZ);
			curve = YJKLineEx.YJKGetBound(ptBase1 + xyz3 * 0.5 * dTextH, ptBase1 - xyz3 * 0.5 * dTextH);
			lstLine.Add(new CurveInfo(curve, Color, 1f));
			curve = YJKLineEx.YJKGetBound(ptBase2 + xyz3 * 0.5 * dTextH, ptBase2 - xyz3 * 0.5 * dTextH);
			lstLine.Add(new CurveInfo(curve, Color, 1f));
			curve = YJKLineEx.YJKGetBound(ptBase1, ptBase2);
			lstLine.Add(new CurveInfo(curve, Color, 1f));
			double num = XYZ.BasisX.AngleOnPlaneTo(xyz, XYZ.BasisZ);
			if (num > Math.PI*.5 && num <= 4.71238898038469)
			{
				num += Math.PI;
			}
			if (num >= Math.PI*2)
			{
				num -= Math.PI*2;
			}
			double num2 = ((double)sDimText.Length + 2.2) * dTextH;
			XYZ xyz4;
			if (num2 < ptBase1.DistanceTo(ptBase2))
			{
				xyz4 = ptBase1 + (ptBase2 - ptBase1) / 2.0;
			}
			else
			{
				xyz4 = ptBase2 + xyz * num2 / 2.0;
			}
			xyz4 += xyz2 * 1.2 * dTextH;
			TextNoteInfo item = new TextNoteInfo(sDimText, Color, dTextH, xyz4, num2, 1.5 * dTextH, num);
			lstText.Add(item);
		}

		private void DrawArrow(List<Line> lstPath, double dArrowLen, PenColor Color, List<CurveInfo> lstLine)
		{
			Line curve = null;
			for (int i = 0; i < lstPath.Count; i++)
			{
				Line curve2 = lstPath[i];
				XYZ xyz = curve2.GetEndPoint(0);
				XYZ xyz2 = curve2.GetEndPoint(1);
				XYZ xyz3 = (xyz2 - xyz).Normalize();
				if (i == 0)
				{
					xyz -= xyz3 * dArrowLen;
				}
				if (i == lstPath.Count - 1)
				{
					xyz2 += xyz3 * dArrowLen * 2.0;
				}
				curve = YJKLineEx.YJKGetBound(xyz, xyz2);
				lstLine.Add(new CurveInfo(curve, Color, 1f));
			}
			XYZ hyendPoint = curve.GetEndPoint(0);
			XYZ hyendPoint2 = curve.GetEndPoint(1);
			XYZ xyz4 = (hyendPoint2 - hyendPoint).Normalize();
			XYZ xyz5 = Geometry.RotateTo(xyz4, Math.PI*.5, XYZ.BasisZ);
			XYZ xyz6 = hyendPoint2 - xyz4 * dArrowLen;
			curve = YJKLineEx.YJKGetBound(xyz6 + xyz5 * dArrowLen / 6.0, hyendPoint2);
			lstLine.Add(new CurveInfo(curve, Color, 1f));
			curve = YJKLineEx.YJKGetBound(xyz6 - xyz5 * dArrowLen / 6.0, hyendPoint2);
			lstLine.Add(new CurveInfo(curve, Color, 1f));
		}

		private void TransformLines(double dRotaAngle, bool bMirrorX, bool bMirrorY, List<Line> lstLine)
		{
			if (Math.Abs(dRotaAngle) < 0.0001 && !bMirrorX && !bMirrorY)
			{
				return;
			}
			for (int i = 0; i < lstLine.Count; i++)
			{
				Line curve = lstLine[i];
				XYZ xyz = curve.GetEndPoint(0);
				XYZ xyz2 = curve.GetEndPoint(1);
				if (bMirrorX)
				{
					xyz = new XYZ(-xyz.X, xyz.Y, xyz.Z);
					xyz2 = new XYZ(-xyz2.X, xyz2.Y, xyz2.Z);
				}
				if (bMirrorY)
				{
					xyz = new XYZ(xyz.X, -xyz.Y, xyz.Z);
					xyz2 = new XYZ(xyz2.X, -xyz2.Y, xyz2.Z);
				}
				if (dRotaAngle > 0.0001)
				{
					xyz = Geometry.RotateTo(xyz, dRotaAngle, XYZ.BasisZ);
					xyz2 = Geometry.RotateTo(xyz2, dRotaAngle, XYZ.BasisZ);
				}
				lstLine[i] = YJKLineEx.YJKGetBound(xyz, xyz2);
			}
		}

		private void TransformElements(double dRotaAngle, bool bMirrorX, bool bMirrorY, List<CurveInfo> lstLine, List<TextNoteInfo> lstText)
		{
			if (Math.Abs(dRotaAngle) < 0.0001 && !bMirrorX && !bMirrorY)
			{
				return;
			}
			for (int i = 0; i < lstLine.Count; i++)
			{
				CurveInfo curveInfo = lstLine[i];
				Line line = (Line)curveInfo.CurveObj;
				if (!(line == null))
				{
					XYZ xyz = line.GetEndPoint(0);
					XYZ xyz2 = line.GetEndPoint(1);
					if (bMirrorX)
					{
						xyz = new XYZ(-xyz.X, xyz.Y, xyz.Z);
						xyz2 = new XYZ(-xyz2.X, xyz2.Y, xyz2.Z);
					}
					if (bMirrorY)
					{
						xyz = new XYZ(xyz.X, -xyz.Y, xyz.Z);
						xyz2 = new XYZ(xyz2.X, -xyz2.Y, xyz2.Z);
					}
					if (dRotaAngle > 0.0001)
					{
						xyz = Geometry.RotateTo(xyz, dRotaAngle, XYZ.BasisZ);
						xyz2 = Geometry.RotateTo(xyz2, dRotaAngle, XYZ.BasisZ);
					}
					line = YJKLineEx.YJKGetBound(xyz, xyz2);
					lstLine[i] = new CurveInfo(line, curveInfo.Color, curveInfo.LineWidth);
				}
			}
			for (int j = 0; j < lstText.Count; j++)
			{
				TextNoteInfo textNoteInfo = lstText[j];
				XYZ xyz3 = textNoteInfo.m_Center;
				XYZ xyz4 = Geometry.RotateTo(XYZ.BasisX, textNoteInfo.m_Angle, XYZ.BasisZ);
				XYZ xyz5 = xyz3 + xyz4 * 100.0;
				if (bMirrorX)
				{
					xyz3 = new XYZ(-xyz3.X, xyz3.Y, xyz3.Z);
					xyz5 = new XYZ(-xyz5.X, xyz5.Y, xyz5.Z);
				}
				if (bMirrorY)
				{
					xyz3 = new XYZ(xyz3.X, -xyz3.Y, xyz3.Z);
					xyz5 = new XYZ(xyz5.X, -xyz5.Y, xyz5.Z);
				}
				if (dRotaAngle > 0.0001)
				{
					xyz3 = Geometry.RotateTo(xyz3, dRotaAngle, XYZ.BasisZ);
					xyz5 = Geometry.RotateTo(xyz5, dRotaAngle, XYZ.BasisZ);
				}
				double num = XYZ.BasisX.AngleOnPlaneTo(xyz5 - xyz3, XYZ.BasisZ);
				if (num > Math.PI*.5 && num <= 4.71238898038469)
				{
					num += Math.PI;
				}
				if (num >= Math.PI*2)
				{
					num -= Math.PI*2;
				}
				lstText[j] = new TextNoteInfo(textNoteInfo.m_Text, textNoteInfo.m_Color, textNoteInfo.m_Height, xyz3, textNoteInfo.m_BoundingBoxWidth, textNoteInfo.m_BoundingBoxHeight, num);
			}
		}

		private bool ReadDlgData()
		{
			string tempPath = Path.GetTempPath();
			string path = tempPath + "BarrierFreeRamp.dat";
			if (!File.Exists(path))
			{
				return true;
			}
			FileStream fileStream = new FileStream(path, FileMode.Open);
			StreamReader streamReader = new StreamReader(fileStream);
			streamReader.BaseStream.Seek(0L, SeekOrigin.Begin);
			try
			{
				this.m_nTopElev = Convert.ToInt32(streamReader.ReadLine());
				this.m_strRampSlope = streamReader.ReadLine();
				this.m_nMaxHeight = Convert.ToInt32(streamReader.ReadLine());
				this.m_nRampWidth = Convert.ToInt32(streamReader.ReadLine());
				this.m_nPlatWidth = Convert.ToInt32(streamReader.ReadLine());
				this.m_nFloorThick = Convert.ToInt32(streamReader.ReadLine());
				this.m_nRampLength1 = Convert.ToInt32(streamReader.ReadLine());
				this.m_nRampLength2 = Convert.ToInt32(streamReader.ReadLine());
				this.m_nRampLength3 = Convert.ToInt32(streamReader.ReadLine());
				this.m_nRampLength4 = Convert.ToInt32(streamReader.ReadLine());
				this.m_bSymmetric = Convert.ToBoolean(streamReader.ReadLine());
				this.m_strRampStructStyle = streamReader.ReadLine();
				this.m_strRampStyle = streamReader.ReadLine();
				this.m_strMaterial = streamReader.ReadLine();
				this.m_bDrawRailingLeft = Convert.ToBoolean(streamReader.ReadLine());
				this.m_bDrawRailingRight = Convert.ToBoolean(streamReader.ReadLine());
				this.m_bTurnUpDown = Convert.ToBoolean(streamReader.ReadLine());
				this.m_bTurnLeftRight = Convert.ToBoolean(streamReader.ReadLine());
				this.m_bMarkDirection = Convert.ToBoolean(streamReader.ReadLine());
				this.m_dDrawAngle = Convert.ToDouble(streamReader.ReadLine());
				this.m_nPosionIndex = Convert.ToInt32(streamReader.ReadLine());
			}
			catch
			{
			}
			streamReader.Close();
			fileStream.Close();
			return true;
		}

		public void SaveDlgData()
		{
			string tempPath = Path.GetTempPath();
			string path = tempPath + "BarrierFreeRamp.dat";
			FileStream fileStream = new FileStream(path, FileMode.Create);
			StreamWriter streamWriter = new StreamWriter(fileStream);
			streamWriter.WriteLine(this.m_nTopElev);
			streamWriter.WriteLine(this.m_strRampSlope);
			streamWriter.WriteLine(this.m_nMaxHeight);
			streamWriter.WriteLine(this.m_nRampWidth);
			streamWriter.WriteLine(this.m_nPlatWidth);
			streamWriter.WriteLine(this.m_nFloorThick);
			streamWriter.WriteLine(this.m_nRampLength1);
			streamWriter.WriteLine(this.m_nRampLength2);
			streamWriter.WriteLine(this.m_nRampLength3);
			streamWriter.WriteLine(this.m_nRampLength4);
			streamWriter.WriteLine(this.m_bSymmetric);
			streamWriter.WriteLine(this.m_strRampStructStyle);
			streamWriter.WriteLine(this.m_strRampStyle);
			streamWriter.WriteLine(this.m_strMaterial);
			streamWriter.WriteLine(this.m_bDrawRailingLeft);
			streamWriter.WriteLine(this.m_bDrawRailingRight);
			streamWriter.WriteLine(this.m_bTurnUpDown);
			streamWriter.WriteLine(this.m_bTurnLeftRight);
			streamWriter.WriteLine(this.m_bMarkDirection);
			streamWriter.WriteLine(this.m_dDrawAngle);
			streamWriter.WriteLine(this.m_nPosionIndex);
			streamWriter.Flush();
			streamWriter.Close();
			fileStream.Close();
		}

		private void SetDlgItemData()
		{
			this.txtTopLevel.Text = Convert.ToString(this.m_nTopElev);
			this.txtRampWidth.Text = Convert.ToString(this.m_nRampWidth);
			this.txtPlatWidth.Text = Convert.ToString(this.m_nPlatWidth);
			this.txtRampLength1.Text = Convert.ToString(this.m_nRampLength1);
			this.txtRampLength2.Text = Convert.ToString(this.m_nRampLength2);
			this.txtRampLength3.Text = Convert.ToString(this.m_nRampLength3);
			this.txtRampLength4.Text = Convert.ToString(this.m_nRampLength4);
			this.txtDrawAngle.Text = this.m_dDrawAngle.ToString("f2");
			this.cmbMaxHeight.SelectedText = Convert.ToString(this.m_nMaxHeight);
			this.cmbRampThick.SelectedText = Convert.ToString(this.m_nFloorThick);
			this.cmbSlope.SelectedText = this.m_strRampSlope;
			this.cmbStructStyle.SelectedItem = this.m_strRampStructStyle;
			this.cmbRampStyle.SelectedItem = this.m_strRampStyle;
			this.cmbRailingLeft.SelectedItem = this.m_strRailingNameLeft;
			this.cmbRailingRight.SelectedItem = this.m_strRailingNameRight;
			this.txtRampMaterial.Text = this.m_strMaterial;
			this.chkSymmetric.Checked = this.m_bSymmetric;
			this.chkRailingLeft.Checked = this.m_bDrawRailingLeft;
			this.chkRailingRight.Checked = this.m_bDrawRailingRight;
			this.chkTurnUpDown.Checked = this.m_bTurnUpDown;
			this.chkTrunLeftRight.Checked = this.m_bTurnLeftRight;
			this.chkMarkDirection.Checked = this.m_bMarkDirection;
		}

		private bool GetDlgItemData()
		{
			this.m_nTopElev = Convert.ToInt32(this.txtTopLevel.Text);
			this.m_nRampWidth = Convert.ToInt32(this.txtRampWidth.Text);
			this.m_nPlatWidth = Convert.ToInt32(this.txtPlatWidth.Text);
			this.m_nRampLength1 = Convert.ToInt32(this.txtRampLength1.Text);
			this.m_nRampLength2 = Convert.ToInt32(this.txtRampLength2.Text);
			this.m_nRampLength3 = Convert.ToInt32(this.txtRampLength3.Text);
			this.m_nRampLength4 = Convert.ToInt32(this.txtRampLength4.Text);
			this.m_dDrawAngle = Convert.ToDouble(this.txtDrawAngle.Text);
			this.m_nMaxHeight = Convert.ToInt32(this.cmbMaxHeight.Text);
			this.m_nFloorThick = Convert.ToInt32(this.cmbRampThick.Text);
			this.m_strRampSlope = this.cmbSlope.Text;
			this.m_strRampStructStyle = this.cmbStructStyle.Text;
			this.m_strRampStyle = this.cmbRampStyle.Text;
			this.m_strRailingNameLeft = this.cmbRailingLeft.Text;
			this.m_strRailingNameRight = this.cmbRailingRight.Text;
			this.m_strMaterial = this.txtRampMaterial.Text;
			this.m_bSymmetric = this.chkSymmetric.Checked;
			this.m_bDrawRailingLeft = this.chkRailingLeft.Checked;
			this.m_bDrawRailingRight = this.chkRailingRight.Checked;
			this.m_bTurnUpDown = this.chkTurnUpDown.Checked;
			this.m_bTurnLeftRight = this.chkTrunLeftRight.Checked;
			this.m_bMarkDirection = this.chkMarkDirection.Checked;
			this.m_lstRampLen = new List<double>();
			if (this.m_lstBaseLine.Count > 0)
			{
				this.m_lstRampLen.Add(this.RampLength1);
			}
			if (this.m_lstBaseLine.Count > 1)
			{
				this.m_lstRampLen.Add(this.RampLength2);
			}
			if (this.m_lstBaseLine.Count > 2)
			{
				this.m_lstRampLen.Add(this.RampLength3);
			}
			if (this.m_lstBaseLine.Count > 3)
			{
				this.m_lstRampLen.Add(this.RampLength4);
			}
			return true;
		}

		private void txtTopLevel_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void cmbMaxHeight_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void txtRampWidth_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void txtPlatWidth_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void cmbRampThick_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void txtDrawAngle_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b' && e.KeyChar != '.')
			{
				e.Handled = true;
			}
		}

		private void txtSlopeLength1_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void txtSlopeLength2_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void txtSlopeLength3_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void txtSlopeLength4_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (!char.IsNumber(e.KeyChar) && e.KeyChar != '\r' && e.KeyChar != '\b')
			{
				e.Handled = true;
			}
		}

		private void txtTopLevel_Validating(object sender, CancelEventArgs e)
		{
			try
			{
				int.Parse(this.txtTopLevel.Text);
			}
			catch
			{
				YJKMessageBox.Show("坡道顶部标高输入值无效.");
				this.txtTopLevel.Text = this.m_nTopElev.ToString();
				e.Cancel = true;
			}
		}

		private void cmbSlope_Validating(object sender, CancelEventArgs e)
		{
			try
			{
				string text = this.cmbSlope.Text;
				if (text.Length < 3 || text.Substring(0, 2) != "1:")
				{
					YJKMessageBox.Show("坡度输入值无效.");
					this.cmbSlope.Text = this.m_strRampSlope;
					e.Cancel = true;
				}
				else
				{
					this.m_strRampSlope = text;
					int rampSlope = this.RampSlope;
					if (rampSlope <= 0)
					{
						YJKMessageBox.Show("坡度应该大于零");
						this.cmbSlope.Text = BarrierFreeRampForm.m_lstRampSlope[0];
						this.m_strRampSlope = this.cmbSlope.Text;
						e.Cancel = true;
					}
					else if (rampSlope == this.m_nSlope)
					{
						return;
					}
					this.InitSlopeMaxValue();
					if (this.m_nMaxHeight > this.m_nSlopeMaxHeight)
					{
						YJKMessageBox.Show(string.Format("最大高度大于 GB 50763-2012中当前坡度下允许的最大高度值{0}。", this.m_nSlopeMaxHeight));
					}
					string text2 = "";
					if (this.m_nRampLength1 > this.m_nSlopeMaxLength)
					{
						text2 += "坡段1 ";
					}
					if (this.m_nRampLength2 > this.m_nSlopeMaxLength)
					{
						text2 += "坡段2 ";
					}
					if (this.m_nRampLength3 > this.m_nSlopeMaxLength)
					{
						text2 += "坡段3 ";
					}
					if (this.m_nRampLength4 > this.m_nSlopeMaxLength)
					{
						text2 += "坡段4 ";
					}
					if (text2.Length > 0)
					{
						string str = string.Format("{0}", this.m_nSlopeMaxLength);
						YJKMessageBox.Show(text2 + "长度大于 GB 50763-2012中当前坡度下允许的最大长度" + str);
					}
				}
			}
			catch
			{
				YJKMessageBox.Show("坡度输入值无效.");
				this.cmbSlope.Text = BarrierFreeRampForm.m_lstRampSlope[0];
				e.Cancel = true;
			}
		}

		private void cmbMaxHeight_Validating(object sender, CancelEventArgs e)
		{
			try
			{
				int num = int.Parse(this.cmbMaxHeight.Text);
				if (num <= 0)
				{
					YJKMessageBox.Show("最大高度应该大于零");
					this.cmbMaxHeight.Text = this.m_nMaxHeight.ToString();
					e.Cancel = true;
				}
				else
				{
					if (num > this.m_nSlopeMaxHeight && num != this.m_nMaxHeight)
					{
						YJKMessageBox.Show(string.Format("最大高度大于 GB 50763-2012中当前坡度下允许的最大高度值{0}。", this.m_nSlopeMaxHeight));
					}
					this.m_nMaxHeight = num;
				}
			}
			catch
			{
				YJKMessageBox.Show("最大高度输入值无效.");
				this.cmbMaxHeight.Text = this.m_nMaxHeight.ToString();
				e.Cancel = true;
			}
		}

		private void txtRampWidth_Validating(object sender, CancelEventArgs e)
		{
			try
			{
				int num = int.Parse(this.txtRampWidth.Text);
				if (num < 1200)
				{
					YJKMessageBox.Show("数值不满足 GB 50763-2012中,坡道宽度不应低于1200");
					this.txtRampWidth.Text = this.m_nRampWidth.ToString();
					e.Cancel = true;
				}
				else if (num > this.m_nPlatWidth)
				{
					if (this.m_strRampStyle == "直线型")
					{
						this.txtPlatWidth.Text = num.ToString();
						this.m_nPlatWidth = num;
						this.m_nRampWidth = num;
					}
					else
					{
						YJKMessageBox.Show("坡道宽度不应大于平台宽度，如有必要请先调整平台宽度");
						this.txtRampWidth.Text = this.m_nRampWidth.ToString();
						e.Cancel = true;
					}
				}
				else
				{
					this.m_nRampWidth = num;
				}
			}
			catch
			{
				YJKMessageBox.Show("坡道宽度输入值无效.");
				this.txtRampWidth.Text = this.m_nRampWidth.ToString();
				e.Cancel = true;
			}
		}

		private void txtPlatWidth_Validating(object sender, CancelEventArgs e)
		{
			try
			{
				int num = int.Parse(this.txtPlatWidth.Text);
				if (num < 1500)
				{
					YJKMessageBox.Show("数值不满足 GB 50763-2012中,平台宽度不应低于1500");
					this.txtPlatWidth.Text = this.m_nPlatWidth.ToString();
					e.Cancel = true;
				}
				else if (num < this.m_nRampWidth)
				{
					YJKMessageBox.Show("平台宽度不应低于坡道净宽");
					this.txtPlatWidth.Text = this.m_nPlatWidth.ToString();
					e.Cancel = true;
				}
				else
				{
					this.m_nPlatWidth = num;
				}
			}
			catch
			{
				YJKMessageBox.Show("平台宽度输入值无效.");
				this.txtPlatWidth.Text = this.m_nPlatWidth.ToString();
				e.Cancel = true;
			}
		}

		private void cmbRampThick_Validating(object sender, CancelEventArgs e)
		{
			try
			{
				int num = int.Parse(this.cmbRampThick.Text);
				if (num <= 0)
				{
					YJKMessageBox.Show("坡道厚度必须大于零");
					this.cmbRampThick.Text = this.m_nFloorThick.ToString();
					e.Cancel = true;
				}
				else
				{
					this.m_nFloorThick = num;
				}
			}
			catch
			{
				YJKMessageBox.Show("坡度厚度输入值无效.");
				this.cmbRampThick.Text = this.m_nFloorThick.ToString();
				e.Cancel = true;
			}
		}

		private void txtSlopeLength1_Validating(object sender, CancelEventArgs e)
		{
			try
			{
				int num = int.Parse(this.txtRampLength1.Text);
				if (num < 0)
				{
					YJKMessageBox.Show("坡段1长度不应低于0");
					this.txtRampLength1.Text = this.m_nRampLength1.ToString();
					e.Cancel = true;
				}
				else
				{
					if (this.m_nRampLength1 > this.m_nSlopeMaxLength && this.m_nRampLength1 != num)
					{
						YJKMessageBox.Show(string.Format("坡段1长度大于 数值不满足 GB 50763-2012中当前坡度下允许的最大长度{0}", this.m_nSlopeMaxLength));
					}
					this.m_nRampLength1 = num;
					if (this.m_bSymmetric)
					{
						this.m_nRampLength3 = num;
					}
				}
			}
			catch
			{
				YJKMessageBox.Show("坡段1长度输入值无效.");
				this.txtRampLength1.Text = this.m_nRampLength1.ToString();
				e.Cancel = true;
			}
		}

		private void txtSlopeLength2_Validating(object sender, CancelEventArgs e)
		{
			try
			{
				int num = int.Parse(this.txtRampLength2.Text);
				if (num < 0)
				{
					YJKMessageBox.Show("坡段2长度不应低于0");
					this.txtRampLength2.Text = this.m_nRampLength2.ToString();
					e.Cancel = true;
				}
				else
				{
					if (this.m_nRampLength2 > this.m_nSlopeMaxLength && this.m_nRampLength2 != num)
					{
						YJKMessageBox.Show(string.Format("坡段2长度大于 GB 50763-2012中当前坡度下允许的最大长度{0}", this.m_nSlopeMaxLength));
					}
					this.m_nRampLength2 = num;
					if (this.m_bSymmetric)
					{
						this.m_nRampLength4 = num;
					}
				}
			}
			catch
			{
				YJKMessageBox.Show("坡段2长度输入值无效.");
				this.txtRampLength2.Text = this.m_nRampLength2.ToString();
				e.Cancel = true;
			}
		}

		private void txtSlopeLength3_Validating(object sender, CancelEventArgs e)
		{
			try
			{
				int num = int.Parse(this.txtRampLength3.Text);
				if (num < 0)
				{
					YJKMessageBox.Show("坡段3长度不应低于0");
					this.txtRampLength3.Text = this.m_nRampLength3.ToString();
					e.Cancel = true;
				}
				else
				{
					if (this.m_nRampLength3 > this.m_nSlopeMaxLength && this.m_nRampLength3 != num)
					{
						YJKMessageBox.Show(string.Format("坡段3长度大于 GB 50763-2012中当前坡度下允许的最大长度{0}", this.m_nSlopeMaxLength));
					}
					this.m_nRampLength3 = num;
				}
			}
			catch
			{
				YJKMessageBox.Show("坡段3长度输入值无效.");
				this.txtRampLength3.Text = this.m_nRampLength3.ToString();
				e.Cancel = true;
			}
		}

		private void txtSlopeLength4_Validating(object sender, CancelEventArgs e)
		{
			try
			{
				int num = int.Parse(this.txtRampLength4.Text);
				if (num < 0)
				{
					YJKMessageBox.Show("坡段4长度不应低于0");
					this.txtRampLength4.Text = this.m_nRampLength4.ToString();
					e.Cancel = true;
				}
				else
				{
					if (this.m_nRampLength4 > this.m_nSlopeMaxLength && this.m_nRampLength4 != num)
					{
						YJKMessageBox.Show(string.Format("坡段4长度大于 GB 50763-2012中当前坡度下允许的最大长度{0}", this.m_nSlopeMaxLength));
					}
					this.m_nRampLength4 = num;
				}
			}
			catch
			{
				YJKMessageBox.Show("坡段4长度输入值无效.");
				this.txtRampLength4.Text = this.m_nRampLength4.ToString();
				e.Cancel = true;
			}
		}

		private void CreateBarrierFreeRampForm_Load(object sender, EventArgs e)
		{
			if (!this.m_bEditRamp)
			{
				this.ReadDlgData();
			}
			this.LoadFamily();
			this.InitComboxData();
			this.InitMaterial();
			this.InitRailSymbol();
			this.InitSlopeMaxValue();
			this.RefreshPreview();
			this.SetDlgItemData();
			this.SetDlgItemEnable();
			//base.Icon = Resource.YArchitechIcon;
		}

		private void btnOK_Click(object sender, EventArgs e)
		{
			this.GetDlgItemData();
			if (!this.m_bEditRamp)
			{
				this.SaveDlgData();
			}
			this.m_nDlgCloseType = BarrierFreeRampForm.ResultType.RT_DrawRamp;
		}

		private void cmbRailingLeft_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.m_strRailingNameLeft = this.cmbRailingLeft.Text;
			foreach (FamilySymbol familySymbol in this.m_lstRailSymbol)
			{
				if (familySymbol.Name == this.m_strRailingNameLeft)
				{
					this.m_leftRailSymbol = familySymbol;
					break;
				}
			}
		}

		private void cmbRailingRight_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.m_strRailingNameRight = this.cmbRailingRight.Text;
			foreach (FamilySymbol familySymbol in this.m_lstRailSymbol)
			{
				if (familySymbol.Name == this.m_strRailingNameRight)
				{
					this.m_rightRailSymbol = familySymbol;
					break;
				}
			}
		}

		private void cmbStructStyle_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.m_strRampStructStyle = this.cmbStructStyle.Text;
			this.SetDlgItemEnable();
		}

		private void btnChangePosition_Click(object sender, EventArgs e)
		{
			this.m_nPosionIndex++;
			this.Refresh();
		}

		private void btnDrawAngle_Click(object sender, EventArgs e)
		{
			this.m_nDlgCloseType = BarrierFreeRampForm.ResultType.RT_GetAngle;
		}

		private void btnSelectMaterial_Click(object sender, EventArgs e)
		{
			Document document = this.m_cmdData.Application.ActiveUIDocument.Document;
			Transaction transaction = new Transaction(document);
			transaction.Start("change info");
			if (MaterialSelectManager.MaterialSelect(document, this.m_idMaterial, ref this.m_idMaterial))
			{
				Material material = this.m_cmdData.Application.ActiveUIDocument.Document.GetElement(this.m_idMaterial) as Material;
				this.m_strMaterial = material.Name;
				this.txtRampMaterial.Text = this.m_strMaterial;
			}
			transaction.Commit();
		}

		private void chkTurnUpDown_CheckedChanged(object sender, EventArgs e)
		{
			this.m_bTurnUpDown = this.chkTurnUpDown.Checked;
			this.Refresh();
		}

		private void chkTrunLeftRight_CheckedChanged(object sender, EventArgs e)
		{
			this.m_bTurnLeftRight = this.chkTrunLeftRight.Checked;
			this.Refresh();
		}

		private void chkSymmetric_CheckedChanged(object sender, EventArgs e)
		{
			this.m_bSymmetric = this.chkSymmetric.Checked;
			if (this.m_bSymmetric)
			{
				this.txtRampLength3.Text = this.txtRampLength1.Text;
				this.txtRampLength4.Text = this.txtRampLength2.Text;
			}
			this.SetDlgItemEnable();
		}

		private void chkMarkDirection_CheckedChanged(object sender, EventArgs e)
		{
			this.m_bMarkDirection = this.chkMarkDirection.Checked;
			this.Refresh();
		}

		private void chkRailingLeft_CheckedChanged(object sender, EventArgs e)
		{
			this.m_bDrawRailingLeft = this.chkRailingLeft.Checked;
			this.cmbRailingLeft.Enabled = this.m_bDrawRailingLeft;
			this.Refresh();
		}

		private void chkRailingRight_CheckedChanged(object sender, EventArgs e)
		{
			this.m_bDrawRailingRight = this.chkRailingRight.Checked;
			this.cmbRailingRight.Enabled = this.m_bDrawRailingRight;
			this.Refresh();
		}

		private void txtDrawAngle_TextChanged(object sender, EventArgs e)
		{
			try
			{
				double num = double.Parse(this.txtDrawAngle.Text);
				if (num < 0.0 || num > 360.0)
				{
					this.txtDrawAngle.Text = this.m_dDrawAngle.ToString("f2");
					return;
				}
				this.m_dDrawAngle = num;
			}
			catch
			{
				this.txtDrawAngle.Text = this.m_dDrawAngle.ToString("f2");
				return;
			}
			this.Refresh();
		}

		private void cmbSlopeStyle_SelectedIndexChanged(object sender, EventArgs e)
		{
			this.m_strRampStyle = this.cmbRampStyle.Text;
			this.SetDlgItemEnable();
			this.Refresh();
		}

		private void txtSlopeLength1_TextChanged(object sender, EventArgs e)
		{
			if (this.m_bSymmetric)
			{
				this.txtRampLength3.Text = this.txtRampLength1.Text;
			}
		}

		private void txtSlopeLength2_TextChanged(object sender, EventArgs e)
		{
			if (this.m_bSymmetric)
			{
				this.txtRampLength4.Text = this.txtRampLength2.Text;
			}
		}

		private void BarrierFreeRampForm_KeyPress(object sender, KeyPressEventArgs e)
		{
			if (e.KeyChar == '\u001b')
			{
				base.Close();
			}
		}

		private List<Line> OffsetLines(List<Line> lstOldLine, double dOffset, bool bOffsetLeft)
		{
			List<Line> list = new List<Line>();
			foreach (Line oldLine in lstOldLine)
			{
				Line item = this.OffsetLine(oldLine, dOffset, bOffsetLeft);
				list.Add(item);
			}
			List<Line> list2 = new List<Line>();
			for (int i = 0; i < list.Count - 1; i++)
			{
				Line line = list[i];
				Line line2 = list[i + 1];
				XYZ xyz = this.ExtenTwoLineIntersect(line, line2);
				Line item2 = YJKLineEx.YJKGetBound(line.GetEndPoint(0), xyz);
				Line value = YJKLineEx.YJKGetBound(xyz, line2.GetEndPoint(1));
				list2.Add(item2);
				list[i + 1] = value;
			}
			Line item3 = list[list.Count - 1];
			list2.Add(item3);
			return list2;
		}

		private Line OffsetLine(Line oldLine, double dOffset, bool bOffsetLeft)
		{
			XYZ hyendPoint = oldLine.GetEndPoint(0);
			XYZ hyendPoint2 = oldLine.GetEndPoint(1);
			int num = bOffsetLeft ? 1 : -1;
			XYZ xyz = Geometry.RotateTo(hyendPoint2 - hyendPoint, (double)num * Math.PI / 2.0, XYZ.BasisZ);
			return YJKLineEx.YJKGetBound(hyendPoint + xyz.Normalize() * dOffset, hyendPoint2 + xyz.Normalize() * dOffset);
		}

		private XYZ ExtenTwoLineIntersect(Line line1, Line line2)
		{
			XYZ result = null;
			Line line3 = YJKLineEx.YJKGetUnBound(line1.GetEndPoint(0), line1.GetEndPoint(1) - line1.GetEndPoint(0));
			Line line4 = YJKLineEx.YJKGetUnBound(line2.GetEndPoint(0), line2.GetEndPoint(1) - line2.GetEndPoint(0));
			IntersectionResultArray intersectionResultArray = new IntersectionResultArray();
            if (line3.Intersect(line4, out intersectionResultArray) == SetComparisonResult.Overlap && intersectionResultArray != null && !intersectionResultArray.IsEmpty)
			{
				result = intersectionResultArray.get_Item(0).XYZPoint;
			}
			return result;
		}

		private static string[] m_lstRampSlope = new string[]
		{
			"1:8",
			"1:9",
			"1:10",
			"1:12",
			"1:16",
			"1:18",
			"1:20"
		};

		private static string[] m_lstRampStruct = new string[]
		{
			"整体",
			"结构板"
		};

		private static string[] m_lstRampStyle = new string[]
		{
			"直线型",
			"直角型",
			"折返型1",
			"折返型2"
		};

		private static string[] m_lstFloorThick = new string[]
		{
			"25",
			"30",
			"50",
			"80",
			"300"
		};

		private ExternalCommandData m_cmdData;

		private ElementId m_idMaterial;

		private FamilySymbol m_leftRailSymbol;

		private FamilySymbol m_rightRailSymbol;

		private FamilySymbol m_endRailSymbol;

		private List<FamilySymbol> m_lstRailSymbol;

		private Previewer m_RampPreviewer;

		public BarrierFreeRampForm.ResultType m_nDlgCloseType;

		public List<Line> m_lstBaseLine;

		public List<double> m_lstRampLen;

		private int m_nSlope;

		private int m_nPosionIndex;

		private int m_nSlopeMaxHeight;

		private int m_nSlopeMaxLength;

		private bool m_bEditRamp;

		private string m_strRampSlope;

		private int m_nTopElev;

		private int m_nMaxHeight = 300;

		private int m_nRampWidth = 1200;

		private int m_nPlatWidth = 1500;

		private int m_nFloorThick = 80;

		private int m_nRampLength1 = 2400;

		private int m_nRampLength2 = 800;

		private int m_nRampLength3 = 1200;

		private int m_nRampLength4 = 800;

		private bool m_bSymmetric;

		private double m_dDrawAngle;

		public string m_strRailingNameLeft;

		public string m_strRailingNameRight;

		public string m_strRampStructStyle = "结构板";

		public string m_strRampStyle = "直线型";

		public string m_strMaterial = "水泥砂浆";

		public bool m_bDrawRailingLeft = true;

		public bool m_bDrawRailingRight = true;

		public bool m_bTurnUpDown;

		public bool m_bTurnLeftRight;

		public bool m_bMarkDirection;

		public enum ResultType
		{
			RT_GetAngle,
			RT_DrawRamp
		}
	}
}
